using System;
using System.Runtime.InteropServices;

namespace Motion.ZmcAct
{

	public class zmotion
	{
		public enum ZMC_CONNECTION_TYPE
		{
			ZMC_CONNECTION_COM = 1,
			ZMC_CONNECTION_ETH,
			ZMC_CONNECTION_USB,
			ZMC_CONNECTION_PCI
		}

		public struct struct_AxisStates
		{
			public byte m_HomeState;

			public byte m_AlarmState;

			public byte m_SDState;

			public byte m_INPState;

			public byte m_ElDecState;

			public byte m_ElPlusState;

			public byte m_HandWheelAState;

			public byte m_HandWheelBState;

			public byte m_EncodeAState;

			public byte m_EncodeBState;

			public byte m_EMGState;

			public byte m_ClearState;

			public byte m_EnableOut;

			public byte m_SoftElDecState;

			public byte m_SoftElPlusState;

			public byte m_LatchAState;

			public byte m_LatchBState;
		}

		public enum ZBASIC_TASKSTATE
		{
			TASK_STATE_RUNING = 1,
			TASK_STATE_PAUSE = 3,
			TASK_STATE_STOP = 0,
			TASK_STATE_STEP = 2,
			TASK_STATE_PAUSING = 4,
			TASK_STATE_STOPING = 5,
			TASK_STATE_ERROR = 100
		}

		public const int ZMC_DEFAULT_TIMEOUT = 1000;

		public const int ZMC_DEFAULT_TIMEOUT_COM = 5000;

		public const int SYS_STATE_CANNOT_CONNECT = 50;

		public const int ZMC_DEFAULT_LEN = 2048;

		[DllImport("zmotion.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
		public static extern int ZMC_Open(ZMC_CONNECTION_TYPE type, string pconnectstring, out IntPtr phandle);

		[DllImport("zmotion.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
		public static extern int ZMC_FastOpen(ZMC_CONNECTION_TYPE type, string pconnectstring, uint uims, out IntPtr phandle);

		[DllImport("zmotion.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
		public static extern int ZMC_OpenCom(uint comid, out IntPtr phandle);

		[DllImport("zmotion.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
		public static extern int ZMC_SetComDefaultBaud(uint dwbaudRate, uint dwByteSize, uint dwParity, uint dwStopBits);

		[DllImport("zmotion.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
		public static extern int ZMC_PeakCom(uint comid, uint uims, out IntPtr phandle);

		[DllImport("zmotion.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
		public static extern int ZMC_OpenEth(string ipaddr, out IntPtr phandle);

		[DllImport("zmotion.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
		public static extern int ZMC_OpenEth2(uint straddr, out IntPtr phandle);

		[DllImport("zmotion.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
		public static extern int ZMC_OpenPci(uint cardnum, out IntPtr Phandle);

		[DllImport("zmotion.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
		public static extern uint ZMC_GetMaxPciCards();

		[DllImport("zmotion.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
		public static extern int ZMC_SearchAndOpenCom(uint uimincomidfind, uint uimaxcomidfind, ref uint uims, out IntPtr phandle);

		[DllImport("zmotion.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
		public static extern int ZMC_SearchAndOpenEth(string ipaddr, uint uims, out IntPtr phandle);

		[DllImport("zmotion.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
		public static extern int ZMC_SearchEth(string ipaddrlist, uint addrbufflength, uint uims);

		[DllImport("zmotion.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
		public static extern int ZMC_Close(IntPtr handle);

		[DllImport("zmotion.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
		public static extern int ZMC_SetTimeOut(IntPtr handle, uint timems);

		[DllImport("zmotion.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
		public static extern int ZMC_GetTimeOut(IntPtr handle, ref uint ptimems);

		[DllImport("zmotion.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi, EntryPoint = "ZMC_Getprogress")]
		public static extern float ZMC_GetProgress(IntPtr handle);

		[DllImport("zmotion.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
		public static extern byte ZMC_GetConnectType(IntPtr handle);

		[DllImport("zmotion.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
		public static extern string ZMC_GetConnectString(IntPtr handle);

		[DllImport("zmotion.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
		public static extern int ZMC_GetState(IntPtr handle, ref byte pstate);

		[DllImport("zmotion.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
		public static extern int ZMC_GetStopPauseTaskid(IntPtr handle, ref byte ptaskid);

		[DllImport("zmotion.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
		public static extern byte ZMC_GetAxises(IntPtr handle);

		[DllImport("zmotion.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
		public static extern int ZMC_ExecuteNoAck(IntPtr handle, string pszCommand, uint uimswait);

		[DllImport("zmotion.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
		public static extern int ZMC_Execute(IntPtr handle, string pszCommand, uint uimswait, byte[] psResponse, uint uiResponseLength);

		[DllImport("zmotion.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
		public static extern int ZMC_ExecuteWaitDown(IntPtr handle, uint uimaxms);

		[DllImport("zmotion.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
		public static extern int ZMC_ExecuteGetReceive(IntPtr handle, string pbuff, uint uimax, ref uint puiread, ref byte pbifExcuteDown);

		[DllImport("zmotion.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
		public static extern uint ZMC_ExecuteGetRemainBuffSpace(IntPtr handle);

		[DllImport("zmotion.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
		public static extern int ZMC_DirectCommand(IntPtr handle, string pszCommand, byte[] psResponse, uint uiResponseLength);

		[DllImport("zmotion.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
		public static extern int ZMC_MakeZar(string pZpjfilename, string pZarfilename, string pPass, uint uid);

		[DllImport("zmotion.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
		public static extern int ZMC_MakeZar2(IntPtr pzpj, string pBasDir, string pZarfilename, string pPass, uint uid);

		[DllImport("zmotion.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
		public static extern int ZMC_DownZar(IntPtr handle, string pfilename, string pfilenameinControl);

		[DllImport("zmotion.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
		public static extern int ZMC_DownMemZar(IntPtr handle, string pbuffer, uint buffsize, string pfilenameinControl);

		[DllImport("zmotion.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
		public static extern int ZMC_RunZarFile(IntPtr handle, string pfilenameinControl);

		[DllImport("zmotion.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
		public static extern int ZMC_Resume(IntPtr handle);

		[DllImport("zmotion.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
		public static extern int ZMC_DownZarToRamAndRun(IntPtr handle, string pfilename);

		[DllImport("zmotion.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
		public static extern int ZMC_DownMemZarToRamAndRun(IntPtr handle, string buffer, uint buffsize);

		[DllImport("zmotion.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
		public static extern int ZMC_MakeZarAndRamRun(string pZpjfilename, string pPass, uint uid);

		[DllImport("zmotion.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
		public static extern int ZMC_MakeZarAndRamRun2(IntPtr handle, IntPtr pzpj, string pBasDir, string pPass, uint uid);

		[DllImport("zmotion.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
		public static extern int ZMC_MakeZarAndDown(string pZpjfilename, string pPass, uint uid);

		[DllImport("zmotion.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi, EntryPoint = "ZMC_MakeZarAndDown")]
		public static extern int ZMC_MakeZarAndDown2(IntPtr handle, IntPtr pzpj, string pBasDir, string pPass, uint uid);

		[DllImport("zmotion.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
		public static extern int ZMC_MakeOneFileZpj(IntPtr pZpjBuff, string pBaDir, string pBasfilename);

		[DllImport("zmotion.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
		public static extern int ZMC_MakeRealZpj(string pZpjfilename, string pbuffer, uint buffsize);

		[DllImport("zmotion.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
		public static extern int ZMC_MakeRealZpjMem(string pBasDir, IntPtr pzpj);

		[DllImport("zmotion.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
		public static extern int ZMC_MakeZlib(string pfilenameBas, string pfilenameZlb);

		[DllImport("zmotion.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
		public static extern int ZMC_GetZlibGlobalDefine(string pfilenameZlb, string pbuffer, uint buffsize);

		[DllImport("zmotion.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
		public static extern int ZMC_UpCurZpjToMem(IntPtr handle, string pbufferm, uint buffsize);

		[DllImport("zmotion.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
		public static extern int ZMC_Pause(IntPtr handle);

		[DllImport("zmotion.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
		public static extern int ZMC_Stop(IntPtr handle);

		[DllImport("zmotion.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
		public static extern int ZMC_Check3File(IntPtr handle, string pfilenameinControl, ref byte pbIfExist, ref uint pFileSize);

		[DllImport("zmotion.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
		public static extern int ZMC_FindFirst3File(int handle, string pfilenameinControl, ref uint pFileSize);

		[DllImport("zmotion.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
		public static extern int ZMC_FindNext3File(int handle, string pfilenameinControl, ref uint pFileSize);

		[DllImport("zmotion.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi, EntryPoint = "ZMC_GetCur3File")]
		public static extern int ZMC_FindNext3File(IntPtr handle, string pfilenameinControl, ref uint pFileSize);

		[DllImport("zmotion.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
		public static extern int ZMC_Delete3File(IntPtr handle, string pfilenameinControl);

		[DllImport("zmotion.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
		public static extern int ZMC_RemoveAll3File(IntPtr handle);

		[DllImport("zmotion.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi, EntryPoint = "ZMC_FlashWrite")]
		public static extern int ZMC_FlashWritef(IntPtr handle, ushort uiflashid, uint uinumes, ref float pfvlue);

		[DllImport("zmotion.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
		public static extern int ZMC_FlashReadf(IntPtr handle, ushort uiflashid, uint uibuffnum, ref float pfvlue, ref uint puinumesread);

		[DllImport("zmotion.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
		public static extern int ZMC_GetCurIpAddr(IntPtr handle, string sIpAddr);

		[DllImport("zmotion.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
		public static extern int ZMC_GetStringType(IntPtr handle, string sname, ushort filenum, ref ushort type, ref uint type2, ref double pvalue);

		[DllImport("zmotion.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
		public static extern int ZMC_Modbus_Set0x(IntPtr handle, ushort start, ushort inum, byte[] pdata);

		[DllImport("zmotion.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
		public static extern int ZMC_Modbus_Get0x(IntPtr handle, ushort start, ushort inum, byte[] pdata);

		[DllImport("zmotion.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
		public static extern int ZMC_Modbus_Get4x(IntPtr handle, ushort start, ushort inum, ushort[] pdata);

		[DllImport("zmotion.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
		public static extern int ZMC_Modbus_Set4x(IntPtr handle, ushort start, ushort inum, ushort[] pdata);

		[DllImport("zmotion.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi, EntryPoint = "ZMC_SetOutput")]
		public static extern int ZMC_Modbus_Set4x(IntPtr handle, ushort inum, ushort iostate);

		[DllImport("zmotion.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
		public static extern int ZMC_GetIn(IntPtr handle, ushort inum, ref byte iostate);

		[DllImport("zmotion.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
		public static extern int ZMC_GetOutput(IntPtr handle, ushort inum, ref byte iostate);
	}
}